package com.ckzp.jfinal.weixin.controller;

import com.ckzp.core.model.Datas;
import com.ckzp.jfinal.base.BaseController;
import com.ckzp.jfinal.form.FormData;
import com.ckzp.jfinal.interceptor.Admins;
import com.ckzp.jfinal.system.model.SysConfig;
import com.ckzp.jfinal.system.util.SysConfigUtil;
import com.ckzp.weixin.WxTool;
import com.jfinal.aop.Clear;

/**
 * Created by 51594 on 2023/3/30.
 */
public class WxMenuController extends BaseController {

    @Admins(roles = "wxadmin", name = "默认", log = false)
    public void index() {
        renderText("默认");
    }


    /**
     * 微信支付流水PAGE
     */
    @Admins(roles = "wxadmin", name = "微信支付流水PAGE", log = false)
    public void EditWxMenu() {
        FormData fd = FormData.dao();
        setAttr("form", fd.addData("wx_menu", SysConfigUtil.n().getConfigValue("wx_menu", "")));
        render("ModifyWxMenu.html");
    }


    /**
     * 保存公众号菜单Api
     */
    @Clear
    @Admins(roles = "wxadmin", name = "保存公众号菜单接口", log = false)
    public void ModifyWxMenuDataApi() {
        Datas data = getDatas();
        String menu = data.getStr("menu");
        String action = data.getStr("action", "");
        System.out.println("data====" + data.toJson());
        System.out.println("menu====" + menu);
        boolean status = SysConfigUtil.n().saveConfigValue("wx_menu", menu);
        if ("submit".equals(action)) {
            System.out.println(WxTool.updateWxMenu(menu));
        }
        renderJson(Json(status, "保存"));
    }
}
